import requests
import random
from fake_useragent import UserAgent

# 方法1
# headers ={
#     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
# }
# url = 'https://www.baidu.com/s?'

# 方法2
# UAlist = [
#     'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
#     'Mozilla/5.0 (Linux; Android 7.1.2; MI 5X; Flow) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/347.0.0.268 Mobile Safari/537.36',
#     'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0'
# ]
# UA = random.choice(UAlist)

# 方法3
UA = UserAgent().random
headers = {'User-Agent':UA}
url = 'https://www.baidu.com/s?'
kw = input("请输入关键字：")
parms = kw
res = requests.get(url,headers=headers,params=parms)
res.encoding ='utf-8'
with open('LNUT.html','wb') as f:
    f.write(res.content)
print(UserAgent().random)

